<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程详情列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>标题：</label>
                            <input type="text" name="title"/>
                            <input type="hidden"  id="courseId" name="courseId" th:value="${courseId}"/>
                            <input type="hidden"  id="parentId" name="parentId" value="0"/>
                            <input type="hidden"  id="detailsType" name="detailsType" value="0"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="addCourseContent()" >
                <i class="fa fa-plus"></i> 添加
            </a>

            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                <i class="fa fa-remove"></i> 删除
            </a>
<!--            <a class="btn btn-warning" onclick="$.table.exportExcel()"-->
<!--               shiro:hasPermission="system:courseContent:export">-->
<!--                <i class="fa fa-download"></i> 导出-->
<!--            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:courseContent:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:courseContent:remove')}]];
    var prefix = ctx + "system/courseContent";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "部门",
            columns: [{
                field: 'selectItem',
                radio: true
            },
                {
                    field: 'id',
                    title: 'Id',
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'tools',
                    title: '教具',
                    formatter: function(value, row, index) {
                        return imgUrl(row);
                    }
                },
                {
                    field: 'remark',
                    width: '20',
                    widthUnit: '%',
                    title: '注意事项'
                },
                {
                    field: 'orderNum',
                    title: '显示顺序'
                },
                {
                    field: 'created',
                    title: '创建时间'
                },
                {
                    field: 'createdName',
                    title: '创建人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.parentType == 1 ){
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="courseParentList(\'' + row.id + '\')"> 子集列表</a> ');
                        }
                        actions.push('<a class="btn btn-primary btn-xs  " href="javascript:void(0)" onclick="onTools(\'' + row.id + '\')"></i>选择教具</a> ');
                        actions.push('<a class="btn btn-success btn-xs  " href="javascript:void(0)" onclick="editCourseContent(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs  " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function addCourseContent() {
        var url = prefix + '/addCourseContent?courseId=' + $('#courseId').val();
        $.modal.open("添加课程内容", url,1200);
    }

    function editCourseContent(id) {
        var url = prefix + '/editCourseContent/' + id;
        $.modal.open("修改课程内容", url,1200);
    }

    function courseParentList(id) {
        var url = prefix + '/courseParentList?id=' + id;
        $.modal.openTab("子详情列表", url,1200);
    }
    function onTools(id) {
        var url =  '/system/courseTool/authTool?contentId=' + id;
        $.modal.open("教具选择", url);
    }
    function imgUrl(row) {
        if (row.tools !=null && row.tools !=''){
            var content ='<a class="btn btn-primary btn-xs  " href="javascript:void(0)" onclick="toolsList(\'' + row.id + '\')"></i>教具列表</a> ';
            return content;
        }else {
            return "";
        }
    }
    function toolsList(id) {
        var url =  '/system/courseTool/idsToolList?contentId=' + id;
        $.modal.openTab("所属教具", url);
    }

</script>
</body>
</html>